<?php

namespace Modules\SmallApi\Http\Controllers;

use HiCommon\Service\CommonService;
use Illuminate\Http\Request;
use Modules\SmallApi\Service\PublicService;


class PublicController extends BaseController
{

    /**
     * 根据城市编码获取城市信息
     */
    public function get_city_infor(Request $request)
    {
        $city = $request->all();
        $arr_list = PublicService::get_city_infor($city);

        return response_json($arr_list);
    }

    /**
     * 获取已经开通的城市
     */
    public function get_open_city()
    {
        $arr_list = PublicService::get_open_city();

        return response_json($arr_list);
    }

    /**
     *市区二级联动
     */
    public function get_area_list(Request $request)
    {
        $cid = $request->all();

        return PublicService::getCityAraeList($cid);
    }

    /**
     * 计算两个地理点的距离
     *
     * @return array|void
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function location_distance_for_two_point(){
       try {
           $arr_input = \Illuminate\Support\Facades\Request::input();
           return CommonService::api_location_distance($arr_input);
       }
       catch (\Exception $exception) {
           return ['state'=>1,'msg'=>'失败','data'=>[],'error'=>$exception->getMessage()];
       }
    }

    /**
     * 呼叫代驾信息回调
     *
     * @return array
     * @author wumengmeng <wu_mengmeng@foxmail.com>
     */
    public function appointment_order_helpdriving_callback(){
        try {
            $arr_input = \Illuminate\Support\Facades\Request::input();
            return CommonService::api_appointment_order_helpdriving_callback($arr_input);
        }
        catch (\Exception $exception) {
            return ['state'=>1,'msg'=>'失败','data'=>[],'error'=>$exception->getMessage()];
        }
    }

    /*今晨代驾订单详情*/
    public function jinchen_helpdriving_order_detail(){
        try {
            $n_id = intval(\Illuminate\Support\Facades\Request::input('id',0));
            return CommonService::jinchen_helpdriving_order_detail($n_id);
        }
        catch (\Exception $exception) {
            return hello_error('失败',[],$exception->getMessage());
        }
    }

    /*年检须知*/
    public function year_check_note(){
        try {
            return CommonService::api_year_check_note();
        }
        catch (\Exception $exception) {
            return hello_error('失败',[],$exception->getMessage());
        }
    }


    /*小程序版本*/
    public function version(){
        try {
            return  hello_success('成功',['version'=>'1.0.6']);
        }
        catch (\Exception $exception) {
            return hello_error('失败',[],$exception->getMessage());
        }
    }

    /*免责声明*/
    public function disclaimer(){
        try {
            return CommonService::disclaimer();
        }
        catch (\Exception $exception) {
            return hello_error('失败',[],$exception->getMessage());
        }
    }

    /**
     * 物流追踪
     * 2019 11 27
     */
    public function logistics_tracking(Request $request)
    {
        $order_id = intval($request->get('order_id', 0));
        $type = intval($request->get('type', 0));

        $res = \Modules\Api\Service\PublicService::logistics_tracking($order_id, $type);

        return response_json($res);
    }
}